<?php
declare(strict_types=1);


namespace yanlongli\TypePHP;

use ArrayAccess;

/**
 * Class TypeArray
 * @package yanlongli\TypePHP
 * @method array _to
 */
class TypeArray extends TypePHP implements ArrayAccess
{
    protected array $data;

    public function __construct(array|self $data = [])
    {
        $this->data = ($data instanceof TypeArray) ? $data->_to() : $data;
    }

    public function offsetExists($offset)
    {
        return $this->data[$offset] ? true : false;
    }

    public function offsetGet($offset)
    {
        return $this->data[$offset] ?? null;
    }

    public function offsetSet($offset, $value)
    {
        $this->data[$offset] = $value;
        return $this;
    }

    public function offsetUnset($offset)
    {
        unset($this->data[$offset]);
        return $this;
    }
}
